#
# Copyright (C) 2008 - 454 Life Sciences
#  

AC_INIT([minirpm],[1.0.051900_0330])

PLATFORM_SUFFIX=lsb

AC_CONFIG_AUX_DIR(config)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(minirpm,$PACKAGE_VERSION)
 	
# FIND LIBTOOL
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_CONFIG_MACRO_DIR([m4])

dnl Configure third party libraries.  Drop tarballs into "3rdParty" to
dnl automatically utilize the libraries.  Otherwise, the system ones will be used

function setup3rdParty()
if test -e $1-$2*.tar.gz ; then
	pushd build
	if ! test -e $1/good; then
	rm -rf $1 $1-$2/
	tar zxf ../$1-$2*.tar.gz
	ln -sf $1-$2*/ $1
	pushd $1
	./configure --prefix=$(pwd)/../../install $3
	make install
	if test $? -eq 0 ; then
		touch good
	fi
	fi
	popd
	popd
fi

pushd 3rdparty

if test -z "$PKG_CONFIG_PATH"; then
	export PKG_CONFIG_PATH=$(pwd)/install/lib/pkgconfig
else
	export PKG_CONFIG_PATH=$(pwd)/install/lib/pkgconfig:$PKG_CONFIG_PATH
fi

mkdir -p install build
dnl These CFLAGS allow any third party libraries to find each other
export CFLAGS="-I$(pwd)/install/include $CFLAGS"
export LDFLAGS="-L$(pwd)/install/lib $LDFLAGS" 

setup3rdParty beecrypt 4.2 "--enable-shared=no --without-java --without-cplusplus \
		 	    --without-python --disable-openmp --disable-threads --disable-aio"
setup3rdParty expat 2.0 "--disable-shared"
setup3rdParty scew 1.1 "--disable-shared --disable-doxygen"
setup3rdParty curl 7.20 "--disable-optimize --enable-debug --enable-curldebug --disable-shared --disable-ldap --disable-ldaps \
		      --disable-dict --disable-telnet --disable-tftp --disable-manual \
		      --disable-thread --disable-sspi --disable-rtsp --disable-pop3 --disable-cookies \
		      --disable-imap --disable-smtp --disable-nonblocking \
		      --without-ldap --without-krb4 --without-spnego --without-ssl \
		      --without-gnutls --without-nss  --without-libssh2"
setup3rdParty libarchive 2.8 "--disable-shared -without-openssl --without-bz2lib  --without-xml2 --without-expat"
setup3rdParty argtable2 1 "--disable-shared"
setup3rdParty uriparser 0.7 "--disable-shared --enable-sizedown --disable-test --disable-doc"

popd

PKG_CHECK_MODULES([SCEW],[scew >= 1.0]) 
AC_SUBST(SCEW_CFLAGS)
AC_SUBST(SCEW_LIBS)

PKG_CHECK_MODULES([CURL],[libcurl >= 7]) 
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)

PKG_CHECK_MODULES([ARGTABLE],[argtable2 >= 12]) 
AC_SUBST(ARGTABLE_CFLAGS)
AC_SUBST(ARGTABLE_LIBS)

PKG_CHECK_MODULES([ARCHIVE],[libarchive >= 2.8.0]) 
AC_SUBST(ARCHIVE_CFLAGS)
AC_SUBST(ARCHIVE_LIBS)

PKG_CHECK_MODULES([URIPARSER],[liburiparser >= 0.7]) 
AC_SUBST(URIPARSER_CFLAGS)
AC_SUBST(URIPARSER_LIBS)

# Libbeecrypt doesn't have a .pc file, so we can't use PKG_CHECK_MODULES

LIBBEECRYPT_CFLAGS=-I$(pwd)/3rdparty/install/include 
LIBBEECRYPT_LIBS="-L$(pwd)/3rdparty/install/lib -lbeecrypt"
AC_SUBST(LIBBEECRYPT_CFLAGS)
AC_SUBST(LIBBEECRYPT_LIBS)


# Checks for libraries.
AC_CHECK_LIB([m], [sin])
AC_CHECK_LIB([z], [compress])

AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

AC_CONFIG_FILES([Makefile])

AC_OUTPUT
